package reflection;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class ClassInfoPrinter {

	public static void printConstructors(Class c) {
		Constructor[] cons = c.getDeclaredConstructors(); 
		for (int i = 0; i < cons.length; i++) {
			Constructor oneCons = cons[i];
			Class[] paramTypes = oneCons.getParameterTypes();
			
			System.out.print(Modifier.toString(oneCons.getModifiers())+" ");
			System.out.print(oneCons.getName() + "(");
			
			for (int j = 0; j < paramTypes.length; j++) {
				if(j>0) System.out.print(",");
				//else if(j==0) System.out.print(" ");
				System.out.print(paramTypes[j].getName());
			}
			System.out.println(")");
		}
	}
	
	public static void printMethods(Class c) {
		Method[] methods = c.getDeclaredMethods();
		for (int i = 0; i < methods.length; i++) {
			Method oneMethod = methods[i];
			Class[] paramTypes = oneMethod.getParameterTypes();
			
			System.out.print(Modifier.toString(oneMethod.getModifiers())+" ");
			System.out.print(oneMethod.getName()+" (");
			
			for (int j = 0; j < paramTypes.length; j++) {
				if(j>0) System.out.print(",");
				System.out.print(paramTypes[j].getName());
			}
			
			System.out.println(")");
		}
	}
	
	public static void printFields(Class c) {
		Field[] fields = c.getDeclaredFields();
		for(int i = 0; i< fields.length; i++) {
			Field f = fields[i];
			System.out.print(Modifier.toString(f.getModifiers())+" ");
			System.out.print(f.getType().getName() + " " + f.getName());
			System.out.println();
		}
	}
	
	public static void main(String[] args) {
		printConstructors(java.lang.String.class);
		printMethods(java.lang.Integer.class);
		printFields(String.class);
	}
}
